package com.usdt.system.service.impl.cp;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.usdt.system.cp.utils.UserAndDeptUtils;
import com.usdt.system.domain.resp.ActivityCustomerRespVO;
import com.usdt.system.service.cp.CustomerService;
import com.usdt.system.service.cp.RequestManageService;

import lombok.extern.slf4j.Slf4j;

@Service
@Slf4j
public class CustomerServiceImpl implements CustomerService{
	
	private final String CUSTOMER_LIST = "/api-v1/customer/list";
	
	@Autowired
	private RequestManageService requestManageService;

	@Override
	public List<ActivityCustomerRespVO> list(String keyWord) {
		List<ActivityCustomerRespVO> result = new ArrayList<ActivityCustomerRespVO>();
		
		Map<String, String> currentUserIdAndDeptId = UserAndDeptUtils.getCurrentUserIdAndDeptId();
		String url = CUSTOMER_LIST+"?currentUserId="+currentUserIdAndDeptId.get("currentUserId")+"&currentDeptId="+currentUserIdAndDeptId.get("currentDeptId");
		String listStr = requestManageService.getMethod(StringUtils.isEmpty(keyWord)?url:(url+"&keyWord="+keyWord), String.class);
		if(StringUtils.isBlank(listStr)) {
			return result;
		}
		List<ActivityCustomerRespVO> list = JSON.parseObject(listStr).getList("data", ActivityCustomerRespVO.class);
		
		return CollectionUtils.isEmpty(list)?result:list;
	}

}
